<template>
  <div class="header-container">
    <div class="r-content">
      <el-dropdown @command="handleCommand">
        <span class="el-dropdown-link">
          <img class="user" :src="userStore.userInfo?.avatar" />
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item command="a">首页</el-dropdown-item>
            <el-dropdown-item command="b">退出</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<script setup>
// 导入userStore
import { useUserStore } from '@/stores/user'
const userStore = useUserStore()
import { useRouter } from 'vue-router'
// 创建router实例
const router = useRouter()
// 处理命令事件的方法
const handleCommand = (command) => {
  if (command === 'a') {
    router.push({ name: 'admin' }) // 跳转到首页
  }
}
</script>

<style lang="scss" scoped>
.header-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 100%;
  background-color: #fd715d;
}

.l-content {
  display: flex;
  align-items: center;

  .el-button {
    margin-right: 20px;
  }

  .text {
    color: #fff;
  }

  :deep(.el-breadcrumb) {
    .el-breadcrumb__inner {
      font-weight: normal;

      &.is-link {
        color: #666; // 非最后一个子项的链接颜色
      }
    }

    &:last-child .el-breadcrumb__inner {
      color: #fff; // 只有最后一个子项变成白色
    }
  }
}

.r-content {
  margin-left: auto;
  padding-right: 20px;

  .user {
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }
}
</style>
